package com.mayavi.action;

import java.util.List;

import com.mayavi.bc.IMovieTagBc;
import com.mayavi.bo.MovieTagBo;
import com.mayavi.dto.MovieTagDto;

public class MovieTagCrudAction {
	private Integer id;
	private MovieTagDto tagDto;
	private List<MovieTagBo> tags;
	private IMovieTagBc tagBc;
	private String action;
	
	public String execute() {
		if ("save".equals(action)) {
			return save();
		} else if ("list".equals(action)) {
			return list();
		} else if ("edit".equals(action)) {
			return edit();
		}
		return list();
	}
	
	public String list() {
		setTags(tagBc.getAllTags());
		return "LIST";
	}

	public String edit() {
		if (id != null && id > 0) {
			MovieTagBo tagBo = tagBc.getTagById(id);
			if (tagBo != null) {
				tagDto = new MovieTagDto(id, tagBo.getName());
			}
		}
		return "EDIT";
	}

	public String save() {
		if (tagDto.getId() == null) {
			tagDto.setCreatedById(1);
		}
		tagDto.setModifiedById(1);
		tagBc.saveTag(tagDto);
		return "REDIRECT";
	}

	/**
	 * @param tags the tags to set
	 */
	public void setTags(List<MovieTagBo> tags) {
		this.tags = tags;
	}

	/**
	 * @return the tags
	 */
	public List<MovieTagBo> getTags() {
		return tags;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public MovieTagDto getTagDto() {
		return tagDto;
	}

	public void setTagDto(MovieTagDto tagDto) {
		this.tagDto = tagDto;
	}

	public IMovieTagBc getTagBc() {
		return tagBc;
	}

	public void setTagBc(IMovieTagBc tagBc) {
		this.tagBc = tagBc;
	}

	public String getAction() {
		return action;
	}

	public void setAction(String action) {
		this.action = action;
	}
	
}
